home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / muibuilder / mb / developer / c / sources_gencodec / gencodec.c next >
Encoding:
C/C++ Source or Header  |  1995-11-17  |  7.8 KB  |  324 lines

  1. #include "Tools.h"
  2. #include "WriteCatalogFiles.h"
  3. #include "WriteExternalFile.h"
  4. #include "WriteGUIFiles.h"
  5. #include "WriteMainFile.h"
  6. #include "GenCodeCGUI.h"
  7. #include <libraries/mui.h>
  8.  
  9. #include <ctype.h>
  10.  
  11. /* Prototypes */
  12. #include <clib/alib_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <exec/memory.h>
  16.  
  17. /* ANSI */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. /* Pragmas */
  23. #include <pragmas/dos_pragmas.h>
  24.  
  25. /* MUIBuilder library */
  26. #include "MB.h"
  27. #include "MB_pragmas.h"
  28. #include "MB_protos.h"
  29.  
  30. extern struct Library * DOSBase;
  31.  
  32. /****************************************************************************************************************/
  33. /*****                                                                                                        *****/
  34. /**                                                Global variables                                                **/
  35. /*****                                                                                                        *****/
  36. /****************************************************************************************************************/
  37.  
  38. ULONG    varnb;                    /* number of variables */
  39.  
  40. BOOL    Code, Env;                /* flags-options */
  41. BOOL    Locale, Declarations;
  42. BOOL    Notifications, Application;
  43. BOOL    ExternalExist = FALSE;
  44. char    *FileName, *CatalogName;/* Strings */
  45. char    *GetString;
  46. char    *GetMBString;
  47.  
  48. FILE    *file;
  49.  
  50. char    *HeaderFile;
  51. char    *GUIFile;
  52. char    *MBDir;
  53. char    *Externals;
  54. char    *MainFile;
  55. char    *Catalog_h_File;
  56. char    *Catalog_c_File;
  57.  
  58. struct ObjApp *Appli;
  59.  
  60. extern void end(void);
  61.  
  62. void Quit(void);
  63.  
  64. /****************************************************************************************************************/
  65. /*****                                                                                                        *****/
  66. /**                                                 Init                                                           **/
  67. /*****                                                                                                        *****/
  68. /****************************************************************************************************************/
  69.  
  70. void Init(void)
  71. {
  72.     HeaderFile         = NULL;
  73.     GUIFile         = NULL;
  74.     MBDir            = NULL;
  75.     Externals         = NULL;
  76.     MainFile        = NULL;
  77.     Catalog_h_File    = NULL;
  78.     Catalog_c_File    = NULL;
  79.  
  80.     /* Get all needed variables */
  81.     MB_Get    (
  82.             MUIB_VarNumber        , &varnb,
  83.             MUIB_Code            , &Code,
  84.             MUIB_Environment    , &Env,
  85.             MUIB_Locale            , &Locale,
  86.             MUIB_Notifications    , &Notifications,
  87.             MUIB_Declarations    , &Declarations,
  88.             MUIB_Application    , &Application,
  89.             MUIB_FileName        , &FileName,
  90.             MUIB_CatalogName    , &CatalogName,
  91.             MUIB_GetStringName    , &GetString,
  92.             TAG_END
  93.         );
  94.  
  95.     if (*FileName=='\0')
  96.     {
  97.         DisplayMsg("Please give a name to your application in the field \"CODE\"\n");
  98.         Quit();
  99.     }
  100.     if (Locale && *CatalogName=='\0')
  101.     {
  102.         DisplayMsg("Please give a catalog name in the field \"CATALOG\"\n");
  103.         Quit();
  104.     }
  105.     if (Locale && *GetString=='\0')
  106.     {
  107.         DisplayMsg("Please give a \"GetString\" name in the field \"GetString\"\n");
  108.         Quit();
  109.     }
  110.  
  111.     /* Create 'GetMBString' name */
  112.     if (strcmp(GetString, "GetMBString") == 0) 
  113.         GetMBString  = "GetMBString2";
  114.     else
  115.         GetMBString = "GetMBString";
  116.  
  117.     /* Create File Names */
  118.     remove_extend(FileName);
  119.  
  120.     if (!(GUIFile = AllocMemory(strlen(FileName)+6)))
  121.     {
  122.         Quit();
  123.     }
  124.     strcpy(GUIFile, FileName);
  125.     add_extend(GUIFile, "GUI.c");
  126.  
  127.     if (!(HeaderFile = AllocMemory(strlen(FileName)+6)))
  128.     {
  129.         Quit();
  130.     }
  131.     strcpy(HeaderFile, FileName);
  132.     add_extend(HeaderFile, "GUI.h");
  133.  
  134.     if (!(Externals = AllocMemory(strlen(FileName)+9)))
  135.     {
  136.         Quit();
  137.     }
  138.     strcpy(Externals, FileName);
  139.     strcat(Externals, "Extern");
  140.     add_extend(Externals, ".h");
  141.  
  142.     if (!(MainFile = AllocMemory(strlen(FileName)+7)))
  143.     {
  144.         Quit();
  145.     }
  146.     strcpy(MainFile, FileName);
  147.     strcat(MainFile, "Main");
  148.     add_extend(MainFile, ".c");
  149.  
  150.     if (!(Catalog_h_File = AllocMemory(strlen(FileName)+7)))
  151.     {
  152.         Quit();
  153.     }
  154.     strcpy(Catalog_h_File, FileName);
  155.     strcat(Catalog_h_File, "_cat");
  156.     add_extend(Catalog_h_File, ".h");
  157.  
  158.     if (!(Catalog_c_File = AllocMemory(strlen(FileName)+7)))
  159.     {
  160.         Quit();
  161.     }
  162.     strcpy(Catalog_c_File, FileName);
  163.     strcat(Catalog_c_File, "_cat");
  164.     add_extend(Catalog_c_File, ".c");
  165.  
  166.     /* Get Current Directory Name */
  167.     if (!(MBDir = GetCurrentDirectory()))
  168.     {
  169.         Quit();
  170.     }
  171. }
  172.  
  173.  
  174. /****************************************************************************************************************/
  175. /*****                                                                                                        *****/
  176. /**                                             FreeFileNameMemory                                                   **/
  177. /*****                                                                                                        *****/
  178. /****************************************************************************************************************/
  179.  
  180. void FreeFileNameMemory(void)
  181. {
  182.     FreeMemory(HeaderFile);
  183.     FreeMemory(GUIFile);
  184.     FreeMemory(Externals);
  185.     FreeMemory(MainFile);
  186.     FreeMemory(MBDir);
  187.     FreeMemory(Catalog_h_File);
  188.     FreeMemory(Catalog_c_File);
  189. }
  190.  
  191. /****************************************************************************************************************/
  192. /*****                                                                                                        *****/
  193. /**                                                 Quit                                                           **/
  194. /*****                                                                                                        *****/
  195. /****************************************************************************************************************/
  196.  
  197. void Quit(void)
  198. {
  199.     FreeFileNameMemory();
  200.     DisposeApp(Appli);
  201.     end();
  202. }
  203.  
  204. /****************************************************************************************************************/
  205. /*****                                                                                                        *****/
  206. /**                                            PrintInfo                                                           **/
  207. /*****                                                                                                        *****/
  208. /****************************************************************************************************************/
  209. void PrintInfo(char *str)
  210. {
  211.     char *msg;
  212.  
  213.     if (!(msg = (char *)AllocMemory(9+strlen(str)+4+1)))
  214.         Quit();    
  215.     sprintf(msg,"Generate %s ...",str);
  216.     set(Appli->TX_Prg_Name,MUIA_Text_Contents,msg);
  217.     FreeMemory(msg);
  218. }
  219.  
  220. /****************************************************************************************************************/
  221. /*****                                                                                                        *****/
  222. /**                                             GenerateCode                                                       **/
  223. /*****                                                                                                        *****/
  224. /****************************************************************************************************************/
  225.  
  226. void GenerateCode(struct ObjApp *App,char *H_Header_Text,char *C_Header_Text,char *Main_Header_Text)
  227. {
  228.     ULONG    Main;
  229.     BPTR    lock;
  230.  
  231.     Appli = App;
  232.  
  233.     Init();
  234.  
  235.     /* test catalog description file if locale */
  236.     if (Locale)
  237.     {
  238.         if (!(lock=Lock(CatalogName,ACCESS_READ)))
  239.         {
  240.             DisplayMsg("The catalog description file doesn't exist !!\nPlease generate it with MUIBuilder");
  241.             Quit();
  242.         }
  243.         UnLock(lock);
  244.     }
  245.  
  246.     if (Declarations)
  247.     {
  248.         PrintInfo(FilePart(HeaderFile));
  249.         WriteHeaderFile(HeaderFile,H_Header_Text,FileName,varnb,Env,Notifications,Locale);
  250.     }
  251.  
  252.     if (Env)
  253.     {
  254.         PrintInfo(FilePart(Externals));
  255.         ExternalExist = WriteExternalFile(Externals,varnb);
  256.     }
  257.  
  258.     PrintInfo(FilePart(GUIFile));
  259.     WriteGUIFile(MBDir,HeaderFile,GUIFile,C_Header_Text,Externals,GetString,GetMBString,varnb,
  260.                  ExternalExist,Env,Locale,Declarations,Code,Notifications);
  261.  
  262.     get(App->CH_Generate_Main_File,MUIA_Selected,&Main);
  263.     if (Main)
  264.     {
  265.         PrintInfo(FilePart(MainFile));
  266.         WriteMainFile(HeaderFile,MainFile,Main_Header_Text,varnb,Locale);
  267.     }
  268.  
  269.     if (Locale)
  270.     {
  271.         ULONG    Catalog;
  272.  
  273.         get(App->CH_Add_new_entries_in_Catalog_Description_File,MUIA_Selected,&Catalog);
  274.         if (Catalog)
  275.         {
  276.             char    *command;
  277.             FILE    *file;
  278.  
  279.             if (!(command=AllocMemory(strlen(MBDir)+1+25+15+strlen(CatalogName)+6+strlen(GetString)+1)))
  280.                 Quit();
  281.  
  282.             strcpy(command,MBDir);
  283.             AddPart(command,"WriteCatalog/WriteCatalog",strlen(MBDir)+1+25+1);
  284.             if (!(file=fopen(command,"r")))
  285.             {
  286.                 char *msg;
  287.  
  288.                 if (!(msg=AllocMemory(15+strlen(command)+1)))
  289.                 {
  290.                     FreeMemory(command);
  291.                     Quit();
  292.                 }
  293.                 sprintf(msg,"Can't find %s !!\n",command);
  294.                 DisplayMsg(msg);
  295.                 FreeMemory(msg);
  296.             }
  297.             fclose(file);
  298.             strcat(command," Reserved CDN \"");
  299.             strcat(command,CatalogName);
  300.             strcat(command,"\" GSN ");
  301.             strcat(command,GetString);
  302.             if (!Execute(command,NULL,NULL))
  303.             {
  304.                 FreeMemory(command);
  305.                 Quit();
  306.             }
  307.  
  308.             FreeMemory(command);
  309.         }
  310.  
  311.         PrintInfo(FilePart(Catalog_h_File));
  312.         if (!Write_Catalog_h_File(Catalog_h_File,CatalogName,GetString))
  313.             Quit();
  314.  
  315.         PrintInfo(FilePart(Catalog_c_File));
  316.         if (!Write_Catalog_c_File(Catalog_c_File,CatalogName,GetString))
  317.             Quit();
  318.     }
  319.  
  320.     set(App->TX_Prg_Name,MUIA_Text_Contents,"");
  321.  
  322.     FreeFileNameMemory();
  323. }
  324.